package main

import (
	"fmt"
	"sort"
)

/*
   map的排序
*/
func main() {
	//创建map
	var studentMap map[string]string
	studentMap = make(map[string]string, 4)
	studentMap["Lisi"] = "李四"
	studentMap["Alice"] = "爱丽丝"
	studentMap["Bob"] = "鲍勃"
	studentMap["Pete"] = "皮特"
	//创建切片
	var mapSlice = make([]string, len(studentMap))
	//将map的key放入切片中
	for k, _ := range studentMap {
		mapSlice = append(mapSlice, k)
	}
	//对切片进行排序
	sort.Strings(mapSlice)
	fmt.Println("排序后的切片", mapSlice)
	for _, k := range mapSlice {
		value := studentMap[k]
		fmt.Println(k, value)
	}

}
